Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(plugin-fetch): check if PerformanceObserver exists #1662

Merged
merged 12 commits into from
Jan 20, 2021

Conversation

mhennoch
Copy link
Contributor

@mhennoch mhennoch commented Nov 9, 2020

Which problem is this PR solving?

  • PerformanceObserver and performance.getEntriesByType are used without checking if they exists and will throw in older browsers (eg, Safari 10). XHR plugin has a check for it.

Short description of the changes

  • Check for browser support before using.

@codecov
Copy link

codecov bot commented Nov 9, 2020

Codecov Report

Merging #1662 (b6b88e1) into master (08d5229) will decrease coverage by 0.20%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##           master    #1662      +/-   ##
==========================================
- Coverage   92.58%   92.38%   -0.21%     
==========================================
  Files         174      157      -17     
  Lines        6045     5108     -937     
  Branches     1286     1091     -195     
==========================================
- Hits         5597     4719     -878     
+ Misses        448      389      -59     
Impacted Files Coverage Δ
...es/opentelemetry-context-zone-peer-dep/src/util.ts
...kages/opentelemetry-exporter-collector/src/util.ts
.../opentelemetry-exporter-collector/src/transform.ts
...emetry-instrumentation-xml-http-request/src/xhr.ts
packages/opentelemetry-web/src/utils.ts
packages/opentelemetry-web/src/types.ts
...ry-context-zone-peer-dep/src/ZoneContextManager.ts
...rumentation/src/platform/browser/old/autoLoader.ts
...-instrumentation-fetch/src/enums/AttributeNames.ts
...lemetry-exporter-collector/src/transformMetrics.ts
... and 7 more

@dyladan
Copy link
Member

dyladan commented Nov 11, 2020

Would like @obecny input on this

@@ -225,7 +228,9 @@ export class FetchPlugin extends core.BasePlugin<Promise<Response>> {
response: FetchResponse
) {
const endTime = core.hrTime();
spanData.observer.disconnect();
if (spanData.observer) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can shorten the whole if to one liner as it was previously just add ?

Suggested change
if (spanData.observer) {
spanData.observer?.disconnect();


describe('when PerformanceObserver is undefined', () => {
beforeEach(done => {
Object.defineProperty(window, 'PerformanceObserver', {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use sandbox.stub for that

@@ -174,6 +174,9 @@ export class FetchPlugin extends core.BasePlugin<Promise<Response>> {
): void {
let resources: PerformanceResourceTiming[] = resourcesObserver.entries;
if (!resources.length) {
if (!performance.getEntriesByType) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add unit test for that - use sandbox

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, wanted to do a cleaner solution but ran into a bunch of issues

@mhennoch mhennoch requested a review from obecny December 16, 2020 16:31
Copy link
Member

@obecny obecny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@dyladan dyladan added the enhancement New feature or request label Dec 22, 2020
@mhennoch
Copy link
Contributor Author

mhennoch commented Jan 4, 2021

Can we merge this? @dyladan @obecny

@dyladan
Copy link
Member

dyladan commented Jan 4, 2021

waiting for one more reviewer. i'm fine to merge without if @obecny is

@mhennoch
Copy link
Contributor Author

Who should I ping to get the third approval @dyladan, @obecny ? Doesn't seem like anyone else will find this on their own.

@mhennoch mhennoch requested a review from Flarna as a code owner January 19, 2021 17:40
@vmarchaud vmarchaud merged commit 6b1285c into open-telemetry:master Jan 20, 2021
pichlermarc pushed a commit to dynatrace-oss-contrib/opentelemetry-js that referenced this pull request Dec 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants